'use strict';
/**
 * @name: mysqldb 方法初始化
 * @description: 根据不同的环境进行封装
 * @version: 0.0.1
 * @author: xiech
 * @Date: 2020-12-10 10:23:41
 * @LastEditors: xiech
 * @LastEditTime: 2020-12-10 10:23:42
 */

const node_mysqldb = require('./node_mysqldb.js');
const mini_mysqldb = require('./mini_mysqldb.js');
const egg_mysqldb = require('./egg_mysqldb.js');

const initmysql = async (ctx) => {
  if (!ctx.mfutil) ctx.mfutil = {};
  if (!ctx.mfutil.db) ctx.mfutil.db = {};
  let mfmysqldb;

  if (ctx.env === 'node') {
    mfmysqldb = await node_mysqldb(ctx);
  } else if (ctx.env === 'egg') {
    mfmysqldb = await egg_mysqldb(ctx);
  } else {
    mfmysqldb = await mini_mysqldb(ctx);
  }
  ctx.mfutil.db.mysql = mfmysqldb;
}

module.exports = {
  initMysql: initmysql,
};